# 发送邮件
import random
import smtplib
from email.mime.text import MIMEText
import string
import sys

'''============第三方SMTP服务============'''
mail_host = "smtp.qq.com"
mail_user = "934673107@qq.com"  # 此处为发件邮箱，用来发送打卡完毕的信息
mail_pass = "rjfjtztggpdvbcih"  # 此处为发件邮箱的密钥
sender = '934673107@qq.com'  # 此处为发件邮箱
'''================End==================='''


def sendmail(mail, pwd):
    receivers = []  # 接收人邮箱
    content = "您重置后的账户密码是[" + pwd + "]，请及时修改密码！"
    title = '兰州大学点餐平台-密码重置'  # 邮件主题
    receivers.append(mail)
    message = MIMEText(content, 'plain', 'utf-8')  # 内容, 格式, 编码
    message['From'] = "{}".format(sender)
    message['To'] = ",".join(receivers)
    message['Subject'] = title

    try:
        smtp_obj = smtplib.SMTP_SSL(mail_host, 465)  # 启用SSL发信, 端口一般是465
        smtp_obj.login(mail_user, mail_pass)  # 登录验证
        smtp_obj.sendmail(sender, receivers, message.as_string())  # 发送
        print("邮件发送成功")
    except smtplib.SMTPException as e:
        print(e, "邮件发送失败")


if __name__ == "__main__":
    sendmail(sys.argv[1], sys.argv[2])
